import '../util/_base_export.dart';

import '../util/app_util.dart';

class ProfileBloc with ChangeNotifier {
  List _addr_list = [];
  List get addr_list => _addr_list;

  void init() {
    _addr_list = [];
    notifyListeners();
  }

//-----------------------------------------//
  addrMaintain(Map<String, dynamic> im_param) async {
    Map<String, dynamic> lm_param = {};
    lm_param.addAll(im_param);

    var lm_result = await AppSession.appReq.futureWrapper(
      ApiConst.httpPost,
      ApiServer.prod + ApiUri.set_address,
      {},
      lm_param,
      true,
      true,
    );

    if (lm_result['ev_error'] == 0)
      return lm_result;
    else if ((lm_result['ev_message'] ?? '').isNotEmpty) {
      AppPopupService.showAlertSimple('E', '出错啦', lm_result['ev_message']);
      return {};
    }
  }

  addrList() async {
    var lm_result = await AppSession.appReq.futureWrapper(
      ApiConst.httpGet,
      ApiServer.prod + ApiUri.address_list,
      {},
      {},
      true,
      true,
    );

    if (lm_result['ev_error'] == 0) {
      _addr_list = lm_result['ev_result']['address_list'];
      notifyListeners();
      return lm_result;
    } else if ((lm_result['ev_message'] ?? '').isNotEmpty) {
      AppPopupService.showAlertSimple('E', '出错啦', lm_result['ev_message']);
      return {};
    }
  }
}
